# $Id: PKGBUILD 87008 2013-03-25 19:16:48Z bpiotrowski $
# Maintainer: Sergej Pupykin <pupykin.s+arch@gmail.com>
# Contributor: Sébastien Luttringer <seblu@archlinux.org>
# Contributor: Anders Bergh <anders1@gmail.com>

pkgbase=luasql
pkgname=('lua-sql-mysql' 'lua-sql-postgres' 'lua-sql-sqlite')
pkgver=2.2.0
pkgrel=3
arch=('i686' 'x86_64')
url='http://www.keplerproject.org/luasql/'
license=('MIT')
makedepends=('lua' 'libmariadbclient' 'postgresql-libs' 'sqlite')
source=("https://github.com/downloads/keplerproject/luasql/luasql-$pkgver.tar.gz"
        'lua52.patch')
md5sums=('59d72db444c6369c936d4f03694db6b7'
         'a1d6083215e7a83cfc08621b6998914c')

build() {
  cd $pkgbase-$pkgver
  patch -p1 < "$srcdir/lua52.patch"
  msg2 'Building sqlite support'
  make T=sqlite3 PREFIX=/usr DRIVER_LIBS='-lsqlite3' DRIVER_INCS='-fPIC -std=c99'
  msg2 'Building PostgreSQL support'
  make T=postgres PREFIX=/usr DRIVER_LIBS='-lpq' DRIVER_INCS='-fPIC'
  msg2 'Building MySQL support'
  make T=mysql PREFIX=/usr DRIVER_LIBS="$(mysql_config --libs)" \
    DRIVER_INCS="$(mysql_config --include) -fPIC"
}

package_lua-sql-mysql() {
  pkgdesc='MySQL module for Lua'
  depends=('lua' 'libmariadbclient')
  conflicts=('luasql-mysql')
  replaces=('luasql-mysql')

  cd $pkgbase-$pkgver
  install -Dm644 src/mysql.so "$pkgdir/usr/lib/lua/5.2/luasql/mysql.so"
  install -Dm644 doc/us/license.html "$pkgdir/usr/share/licenses/$pkgname/license.html"
}

package_lua-sql-postgres() {
  pkgdesc='PostgreSQL module for Lua'
  depends=('lua' 'postgresql-libs')

  cd $pkgbase-$pkgver
  install -Dm644 src/postgres.so "$pkgdir/usr/lib/lua/5.2/luasql/postgres.so"
  install -Dm644 doc/us/license.html "$pkgdir/usr/share/licenses/$pkgname/license.html"
}

package_lua-sql-sqlite() {
  pkgdesc='SQLite module for Lua'
  depends=('lua' 'sqlite')

  cd $pkgbase-$pkgver
  install -Dm644 src/sqlite3.so "$pkgdir/usr/lib/lua/5.2/luasql/sqlite3.so"
  install -Dm644 doc/us/license.html "$pkgdir/usr/share/licenses/$pkgname/license.html"
}

# vim:set ts=2 sw=2 et:
